home *** CD-ROM | disk | FTP | other *** search
/ Java Primer Plus / Java Primer Plus (Waite Group Proess)(1996).iso / java_Win / demo / BouncingHeads / BounceImage.class (.txt) next >
Encoding:
Java Class File  |  1995-12-06  |  2.1 KB  |  107 lines

  1. import java.awt.Dimension;
  2. import java.awt.Graphics;
  3. import java.awt.image.ImageObserver;
  4.  
  5. class BounceImage {
  6.    static float inelasticity = 0.96F;
  7.    // $FF: renamed from: Ax float
  8.    static float field_0;
  9.    // $FF: renamed from: Ay float
  10.    static float field_1 = 2.0E-4F;
  11.    // $FF: renamed from: Ar float
  12.    static float field_2 = 0.9F;
  13.    // $FF: renamed from: x float
  14.    public float field_3;
  15.    // $FF: renamed from: y float
  16.    public float field_4;
  17.    public int width;
  18.    public int height;
  19.    // $FF: renamed from: Vx float
  20.    public float field_5 = 0.1F;
  21.    // $FF: renamed from: Vy float
  22.    public float field_6 = 0.05F;
  23.    public int index;
  24.    // $FF: renamed from: Vr float
  25.    public float field_7 = 0.005F + (float)Math.random() * 0.001F;
  26.    public float findex;
  27.    BounceItem parent;
  28.    static boolean imagesReadIn;
  29.  
  30.    public void play(int var1) {
  31.       if (this.parent.sounds[var1] != null) {
  32.          this.parent.sounds[var1].play();
  33.       }
  34.  
  35.    }
  36.  
  37.    public BounceImage(BounceItem var1) {
  38.       this.parent = var1;
  39.       this.width = 65;
  40.       this.height = 72;
  41.    }
  42.  
  43.    public void move(float var1, float var2) {
  44.       this.field_3 = var1;
  45.       this.field_4 = var2;
  46.    }
  47.  
  48.    public void paint(Graphics var1) {
  49.       int var2 = this.index;
  50.       if (this.parent.bounceimages[var2] == null) {
  51.          var2 = 0;
  52.       }
  53.  
  54.       var1.drawImage(this.parent.bounceimages[var2], (int)this.field_3, (int)this.field_4, (ImageObserver)null);
  55.    }
  56.  
  57.    public void step(long var1) {
  58.       boolean var3 = false;
  59.       boolean var4 = false;
  60.       float var5 = (float)Math.random() * 0.01F - 0.005F;
  61.       this.field_3 = (float)((double)this.field_3 + (double)(this.field_5 * (float)var1) + (double)field_0 / (double)2.0F * (double)var1 * (double)var1);
  62.       this.field_4 = (float)((double)this.field_4 + (double)(this.field_6 * (float)var1) + (double)field_1 / (double)2.0F * (double)var1 * (double)var1);
  63.       if (this.field_3 <= 0.0F) {
  64.          this.field_3 = 0.0F;
  65.          this.field_5 = -this.field_5 * inelasticity + var5;
  66.          var3 = true;
  67.          this.play((int)(Math.random() * (double)3.0F));
  68.       }
  69.  
  70.       Dimension var6 = this.parent.size();
  71.       if (this.field_3 + (float)this.width >= (float)var6.width) {
  72.          this.field_3 = (float)(var6.width - this.width);
  73.          this.field_5 = -this.field_5 * inelasticity + var5;
  74.          var3 = true;
  75.          this.play((int)(Math.random() * (double)3.0F));
  76.       }
  77.  
  78.       if (this.field_4 <= 0.0F) {
  79.          this.field_4 = 0.0F;
  80.          this.field_6 = -this.field_6 * inelasticity + var5;
  81.          var4 = true;
  82.          this.play((int)(Math.random() * (double)3.0F));
  83.       }
  84.  
  85.       if (this.field_4 + (float)this.height >= (float)var6.height) {
  86.          this.field_4 = (float)(var6.height - this.height);
  87.          this.field_5 *= inelasticity;
  88.          this.field_6 = -this.field_6 * inelasticity + var5;
  89.          var4 = true;
  90.       }
  91.  
  92.       this.move(this.field_3, this.field_4);
  93.       this.field_6 += field_1 * (float)var1;
  94.       this.field_5 += field_0 * (float)var1;
  95.       this.findex += this.field_7 * (float)var1;
  96.       if (var3 || var4) {
  97.          this.field_7 *= field_2;
  98.       }
  99.  
  100.       while((double)this.findex <= (double)0.0F) {
  101.          this.findex += (float)this.parent.bounceimages.length;
  102.       }
  103.  
  104.       this.index = (int)this.findex % this.parent.bounceimages.length;
  105.    }
  106. }
  107.